package edu.iss.javaproject.validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.iss.javaproject.exception.UserNotFoundException;
import edu.iss.javaproject.model.Users;
import edu.iss.javaproject.service.LAPService;


@Component
public class LoginValidatorImpl implements LoginValidator {

	@Autowired
	private LAPService lapservice;
	
	@Override
	public Users verifyUser(int id, String password){
		Users user, checkUser;
		try{
			checkUser = lapservice.findByID(id);
			System.out.print(checkUser.getName());
			if(checkUser.getPassword().equals(password)){
				user = checkUser;
			} else {
				user = new Users();
			}
		} catch (UserNotFoundException e){
			user = new Users();
		}
		return user;
	}

	@Override
	public int checkNull(String username){
		int id = 0;
		if(username.length() == 4){
			for(int i = 0; i<4; i++){
				if(!Character.isDigit(username.charAt(i))){
					return id;
				}
			}
		id = Integer.parseInt(username);
		}
		return id;
	}
	
}
